home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / mus / play / tracker_4_31.lzh / tracker / Amiga / scroll_window.c < prev    next >
C/C++ Source or Header  |  1995-05-11  |  7KB  |  241 lines

  1. /* amiga/scroll_window.c 
  2.     vi:ts=3 sw=3:
  3.  */
  4.  
  5. /* $Id: scroll_window.c,v 1.4 1995/05/11 12:29:54 espie Exp espie $
  6.  * $Log: scroll_window.c,v $
  7.  * Revision 1.4  1995/05/11  12:29:54  espie
  8.  * *** empty log message ***
  9.  *
  10.  * Revision 1.3  1995/02/14  16:51:22  espie
  11.  * *** empty log message ***
  12.  *
  13.  * Revision 1.2  1995/02/13  22:05:42  espie
  14.  * The display takes more space taken into account.
  15.  *
  16.  * Revision 1.1  1995/01/13  13:31:35  espie
  17.  * Initial revision
  18.  *
  19.  * Revision 1.4  1994/01/09  04:49:18  Espie
  20.  * Stupid: forgot that a window font can very well be proportional.
  21.  * It's easier to rely on GfxBase->DefaultFont after all.
  22.  * Uncentralized event handling using event management functions.
  23.  * Handle own's clipping without Layers.
  24.  * Use dynamic colours/masks according to current screen.
  25.  * Added forbid_reopen to avoid dangling window.
  26.  *
  27.  */
  28.  
  29. /* The line scroller implemented as a window */
  30.  
  31. #include <assert.h>
  32.  
  33. #include <intuition/screens.h>
  34. #include <graphics/text.h>
  35. #include <graphics/gfxmacros.h>
  36. #include <proto/intuition.h>
  37. #include <proto/exec.h>
  38. #include <proto/graphics.h>
  39. #include <graphics/gfxbase.h>
  40.  
  41. #include "defs.h"
  42. #include "extern.h"
  43. #include "amiga/amiga.h"
  44. #include "prefs.h"
  45.  
  46. ID("$Id: scroll_window.c,v 1.4 1995/05/11 12:29:54 espie Exp espie $")
  47.  
  48. LOCAL void init_scroller(void);
  49. LOCAL void (*INIT)(void) = init_scroller;
  50. LOCAL int forbid_reopen = FALSE;
  51. LOCAL void handle_scroller(GENERIC nothing);
  52.  
  53. XT struct IntuitionBase *IntuitionBase;
  54. XT struct GfxBase *GfxBase;
  55.  
  56. LOCAL struct Screen *pubscreen;
  57.  
  58. /* our window */
  59. LOCAL struct Window *scroll_win = 0;
  60. LOCAL struct TextFont *font;
  61.    
  62.  
  63. /* to build up write masks */
  64. LOCAL ULONG text, highlight, background;
  65.  
  66.  
  67. LOCAL void close_scroller()    
  68.    {
  69.    if (scroll_win)
  70.       {
  71.       remove_signal_handler(scroll_win->UserPort->mp_SigBit);
  72.       CloseWindow(scroll_win);
  73.       }
  74.    scroll_win = 0;               /* and get ready for reopen */
  75.    }
  76.  
  77. LOCAL void really_close_scroller()
  78.    {
  79.    forbid_reopen = TRUE;
  80.    close_scroller();
  81.    }
  82.  
  83. /* graphic niceties: draw vertical lines at the right separation points
  84.  * all the way between y1 and the bottom
  85.  */
  86. LOCAL void separation_lines(int y1)
  87.    {
  88.    int x, xs, i, c;
  89.    
  90.    xs = font->tf_XSize;
  91.    
  92.    SetWrMsk(scroll_win->RPort, background | highlight);  
  93.    SetAPen(scroll_win->RPort, highlight);   
  94.    x = scroll_win->BorderLeft;
  95.    for (i = 1; i < 5; i++)
  96.       {
  97.       if (i == 3)
  98.          x+= xs;
  99.       else
  100.          x += 14 * xs;     /* 14 chars per column */
  101.       c = x - xs/2;
  102.       if (c >= scroll_win->Width - scroll_win->BorderRight -1)
  103.          break;
  104.       Move(scroll_win->RPort, x - xs/2, y1);
  105.       Draw(scroll_win->RPort, x - xs/2, scroll_win->Height - scroll_win->BorderBottom - 1);
  106.       }
  107.    }
  108.    
  109. LOCAL void init_scroller()
  110.    {
  111.    struct DrawInfo *dr;
  112.    
  113.    at_end(really_close_scroller);
  114.       /* default text, background, etc */
  115.    text = 1;
  116.    background = 0;
  117.    highlight = 7;
  118.    pubscreen = obtain_pubscreen();
  119.    dr = GetScreenDrawInfo(pubscreen);
  120.    if (dr)
  121.       {
  122.       if (dr->dri_Version >= 1)  /* for V 2.04 */
  123.          {
  124.          text = dr->dri_Pens[TEXTPEN];
  125.          background = dr->dri_Pens[BACKGROUNDPEN];
  126.          highlight = dr->dri_Pens[SHINEPEN];
  127.          }
  128.       FreeScreenDrawInfo(pubscreen, dr);
  129.       }
  130.    }
  131.    
  132.  
  133. LOCAL void open_scroller()
  134.    {
  135.    INIT_ONCE;
  136.    font = GfxBase->DefaultFont;
  137.    scroll_win = OpenWindowTags(NULL,
  138.       WA_Title, "Scroll",
  139.       WA_DepthGadget, TRUE,
  140.       WA_SmartRefresh, TRUE,
  141.       WA_DragBar, TRUE,
  142.       WA_SizeGadget, TRUE,
  143.       WA_CloseGadget, TRUE,
  144.       WA_InnerWidth, font->tf_XSize * 60, /* 60 = 14 * 4 + some margin */
  145.       WA_InnerHeight, font->tf_YSize * 15,
  146.       WA_MinWidth, 15 * font->tf_XSize,
  147.       WA_MaxWidth, ~0,           /* need some room for the size gadget */
  148.       WA_MinHeight, 2 * (pubscreen->WBorTop + 1 + pubscreen->Font->ta_YSize),   
  149.       WA_MaxHeight, ~0,
  150.       WA_AutoAdjust, TRUE,
  151.       WA_NoCareRefresh, TRUE,
  152.       WA_PubScreen, pubscreen,
  153.       WA_IDCMP, IDCMP_NEWSIZE | IDCMP_CLOSEWINDOW,
  154.       TAG_END);
  155.  
  156.    if (!scroll_win)
  157.       end_all(0);
  158.       
  159.    SetFont(scroll_win->RPort, font);
  160.    install_signal_handler(scroll_win->UserPort->mp_SigBit, handle_scroller, 0);
  161.    separation_lines(scroll_win->BorderTop);
  162.    }
  163.  
  164.  
  165.  
  166. LOCAL void handle_scroller(GENERIC nothing)   
  167.    {
  168.    struct IntuiMessage *msg;
  169.    while (scroll_win && (msg = GetMsg(scroll_win->UserPort)))
  170.       switch(msg->Class)
  171.          {
  172.       case IDCMP_NEWSIZE:
  173.          ReplyMsg(msg);
  174.          separation_lines(scroll_win->BorderTop);  /* redraw lines where applicable */
  175.          break;
  176.       case IDCMP_SIZEVERIFY:
  177.          ReplyMsg(msg);
  178.          break;
  179.       case IDCMP_CLOSEWINDOW:
  180.          ReplyMsg(msg);
  181.          close_scroller();
  182.          set_pref_scalar(PREF_SHOW, FALSE);
  183.          break;
  184.       default:
  185.          ReplyMsg(msg);
  186.          }
  187.    }
  188.  
  189. /* special case: if s is NULL, draw an horizontal line.
  190.  * (separation between patterns) */
  191. void add_scroller(char *s)
  192.    {
  193.    int max_length;
  194.    int x, y;
  195.  
  196.    if (forbid_reopen)
  197.       return;
  198.    if (!scroll_win)
  199.       open_scroller();
  200.       
  201.       /* critical section for size changes */
  202.    ModifyIDCMP(scroll_win, scroll_win->IDCMPFlags | IDCMP_SIZEVERIFY);
  203.    handle_scroller(0);   /* handle size problems first */
  204.  
  205.    if (!scroll_win)     /* window may have closed on us... */
  206.       return;
  207.  
  208.       /* add the characters */
  209.    SetDrMd(scroll_win->RPort, JAM1);
  210.    SetWrMsk(scroll_win->RPort, background | text);
  211.    SetAPen(scroll_win->RPort, text);
  212.    x = scroll_win->BorderLeft;
  213.    y = scroll_win->Height - scroll_win->BorderBottom 
  214.     - font->tf_YSize + font->tf_Baseline;
  215.    Move(scroll_win->RPort, x, y);
  216.    max_length = scroll_win->Width - scroll_win->BorderLeft 
  217.             - scroll_win->BorderRight;
  218.     max_length /= font->tf_XSize;
  219.     if (max_length > 14 * 4)
  220.          max_length = 14 * 4;    /* line length = 14 * 4 */
  221.    if (s)
  222.       Text(scroll_win->RPort, s, max_length);
  223.    else
  224.       Draw(scroll_win->RPort, x + max_length * font->tf_XSize-1, y);
  225.    
  226.       /* add the separation lines */
  227.    separation_lines(scroll_win->Height - scroll_win->BorderBottom 
  228.        - font->tf_YSize);
  229.       
  230.       /* and scroll *JUST* the characters */
  231.    SetWrMsk(scroll_win->RPort, 1);
  232.    ScrollRaster(scroll_win->RPort, 0, font->tf_YSize, 
  233.                   scroll_win->BorderLeft, scroll_win->BorderTop, 
  234.                   scroll_win->Width - scroll_win->BorderRight - 1,
  235.                   scroll_win->Height - scroll_win->BorderBottom - 1);
  236.    
  237.       /* end of critical section: allow resize again */
  238.    ModifyIDCMP(scroll_win, scroll_win->IDCMPFlags & ~IDCMP_SIZEVERIFY);
  239.    handle_scroller(0); 
  240.    }
  241.